import { createStore } from 'vuex'

export default createStore({
  state: {
    list: [
      {
        title: "吃饭",
        complete: false,
      },
      {
        title: "睡觉",
        complete: false,
      },
      {
        title: "敲代码",
        complete: false,
      },
    ]
  },
  getters: {
  },
  //同步修改state
  mutations: {
    //添加任务
    addTodo(state, newItem) {
      state.list.unshift(newItem);
    },
    //删除单个任务 splice(下标, 个数)
    delTodo(state, index) {
      state.list.splice(index, 1);
    },
    //清除已完成
    clear(state, newArr) {
      //把过滤后的数组传进来
      state.list = newArr;
    }
  },
  //异步提交mutation
  //commit是提交mutation 调用mutation的方法
  actions: {
  },
  modules: {
  }
})
